import {
  Controller,
  Delete,
  Get,
  Post,
  Put,
  Body,
  Query,
  Param,
  HttpStatus,
  HttpException,
  UseFilters,
  ParseIntPipe,
} from '@nestjs/common';
import { AppService } from './app.service';
import { HttpExceptionFilter } from './http-exception.filter';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('/data')
  getAllData(@Query() query: { pageIdx: number; pageSize: number }): string {
    return 'get all data' + query.pageIdx + ',' + query.pageSize;
  }

  @Get('/data/:id')
  getData(@Param('id', ParseIntPipe) id: string): string {
    return 'get data' + id;
  }

  @Post('/data')
  addData(@Body() body: NonNullable<unknown>): string {
    return 'add data' + JSON.stringify(body);
  }

  @Put('/data')
  updateData(): string {
    return 'update data';
  }

  @Delete('/data')
  @UseFilters(new HttpExceptionFilter())
  deleteData(): string {
    throw new HttpException('This is a custom message', HttpStatus.FORBIDDEN);
    // return 'delete data';
  }
}
